package com.google.code.p.restrpc.http;

import java.net.URI;

import com.google.code.p.restrpc.http.HttpClientTemplate;
import com.google.code.p.restrpc.http.HttpMethod;
import com.google.code.p.restrpc.http.HttpRequestCallback;
import com.google.code.p.restrpc.http.HttpResponseCallback;

/**
 * @author dz
 */
public class RestTemplate extends HttpClientTemplate {
    
    /**
     * 
     */
    public RestTemplate() {
        super();
    }
    
    /**
     * @param httpClientFactory
     */
    public RestTemplate(HttpClientFactory httpClientFactory) {
        super(httpClientFactory);
    }
    
    /**
     * @param url
     * @param requestCallback
     * @param responseCallback
     * @return
     */
    public Object get(URI url,
                      HttpRequestCallback requestCallback,
                      HttpResponseCallback responseCallback) {
        return execute(url,
                       HttpMethod.GET,
                       requestCallback,
                       responseCallback,
                       null);
    }
    
    /**
     * @param url
     * @param requestCallback
     * @param responseCallback
     * @return
     */
    public Object post(URI url,
                       HttpRequestCallback requestCallback,
                       HttpResponseCallback responseCallback) {
        return execute(url,
                       HttpMethod.POST,
                       requestCallback,
                       responseCallback,
                       null);
    }
    
    /**
     * @param url
     * @param requestCallback
     * @param responseCallback
     * @param errorHandler
     * @return
     */
    public Object get(URI url,
                      HttpRequestCallback requestCallback,
                      HttpResponseCallback responseCallback,
                      ResponseErrorHandler errorHandler) {
        return execute(url,
                       HttpMethod.GET,
                       requestCallback,
                       responseCallback,
                       errorHandler);
    }
    
    /**
     * @param url
     * @param requestCallback
     * @param responseCallback
     * @param errorHandler
     * @return
     */
    public Object post(URI url,
                       HttpRequestCallback requestCallback,
                       HttpResponseCallback responseCallback,
                       ResponseErrorHandler errorHandler) {
        return execute(url,
                       HttpMethod.POST,
                       requestCallback,
                       responseCallback,
                       errorHandler);
    }
    
}
